package com.smart.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smart.admin.common.request.BrandRequestParams;
import com.smart.admin.common.vo.BrandVo;
import com.smart.admin.entity.Brand;
import com.smart.admin.service.BrandService;
import com.smart.common.vo.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * https://cloud.axureshop.com/mg2oq8/#g=1&p=index
 */
@Api(value = "品牌管理")
@RestController
@RequestMapping("/brand")
public class BrandController {
    @Resource
    private BrandService brandService;

    @ApiOperation(value = "添加品牌")
    @PostMapping("/")
    public ResponseResult<Integer> add(@Validated @RequestBody BrandRequestParams brand) {
        int count = brandService.save(brand);
        return ResponseResult.success(count);
    }

    @ApiOperation(value = "查询所有品牌信息")
    @GetMapping("/list")
    public ResponseResult<Page<Brand>> list(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int size) {
        return ResponseResult.success(brandService.list(page, size));
    }

    @ApiOperation(value = "添加品牌")
    @GetMapping("/{id}")
    public ResponseResult<BrandVo> get(@PathVariable int id) {
        return ResponseResult.success(brandService.getBrand(id));
    }

    @ApiOperation(value = "更新品牌信息")
    @PutMapping("/")
    public ResponseResult<Integer> update(@RequestBody BrandRequestParams brandRequestParams) {
        return ResponseResult.success(brandService.update(brandRequestParams));
    }

    @ApiOperation(value = "添加品牌")
    @DeleteMapping("/")
    public ResponseResult<Integer> remove(int id) {
        return ResponseResult.success(brandService.remove(id));
    }

}
